import { Directive } from 'vue';
import { useUserStore } from '../store/user';

export const permission: Directive = {
    mounted(el, binding) {
        const { value } = binding;
        const userInfoStore = useUserStore();
        if ("allPass" === value) return true;
        const permissions = userInfoStore.userInfo.systemRole;
        if (userInfoStore.userInfo.gid === 1 || permissions.includes(value)) {// 
            return true;
        } else {
            el.parentNode && el.parentNode.removeChild(el);
            return false;
        }
        // if (value && value instanceof Array && value.length > 0) {

        //     console.log(value)
        //     const hasPermission = permissions.some((permission: any) => {

        //         return permissionNONE === value[0] || value.includes(permission);// userInfoStore.userInfo.gid === 1 ||
        //     })
        //     if (!hasPermission) {
        //         el.parentNode && el.parentNode.removeChild(el);
        //     }
        // } else {
        //     throw new Error(`请设置操作权限标签值`)
        // }
    }

}

